import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout/index.vue'
import {
  getToken,
  setToken,
  removeToken,
  getStoreId,
  setStoreId,
  removeStoreId,
  setUserInfo,
  getUserInfo,
  removeUserInfo
} from '@/utils/cookies'
import store from '@/store'

Vue.use(Router)

const router = new Router({
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition
    }
    return { x: 0, y: 0 }
  },
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/login',
      component: () =>
        import(/* webpackChunkName: "login" */ '@/views/login/index.vue'),
      meta: { title: 'Ordering system', hidden: true, notNeedAuth: true }
    },
    {
      path: '/404',
      component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue'),
      meta: { title: 'Ordering system', hidden: true, notNeedAuth: true }
    },
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          component: () =>
            import(
              /* webpackChunkName: "dashboard" */ '@/views/dashboard/index.vue'
            ),
          name: 'Dashboard',
          meta: {
            title: 'Service desk',
            icon: 'dashboard',
            affix: true
          }
        },
        {
          path: '/statistics',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/statistics/index.vue'
            ),
          meta: {
            title: 'Order statistics',
            icon: 'icon-statistics'
          }
        },
        {
          path: 'order',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/orderDetails/index.vue'
            ),
          meta: {
            title: 'Order management',
            icon: 'icon-order'
          }
        },
        {
          path: 'setmeal',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/setmeal/index.vue'
            ),
          meta: {
            title: 'Setmeal Management',
            icon: 'icon-combo'
          }
        },
        {
          path: 'dish',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/dish/index.vue'
            ),
          meta: {
            title: 'Dish management',
            icon: 'icon-dish'
          }
        },
        {
          path: '/dish/add',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/dish/addDishtype.vue'
            ),
          meta: {
            title: 'Add dishes',
            hidden: true
          }
        },

        {
          path: 'category',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/category/index.vue'
            ),
          meta: {
            title: 'Category management',
            icon: 'icon-category'
          }
        },
        {
          path: 'employee',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/employee/index.vue'
            ),
          meta: {
            title: 'Employee management',
            icon: 'icon-employee'
          }
        },

        {
          path: '/employee/add',
          component: () =>
            import(
              /* webpackChunkName: "dashboard" */ '@/views/employee/addEmployee.vue'
            ),
          meta: {
            title: 'Add employee',
            hidden: true
          }
        },

        {
          path: '/setmeal/add',
          component: () =>
            import(
              /* webpackChunkName: "shopTable" */ '@/views/setmeal/addSetmeal.vue'
            ),
          meta: {
            title: 'Add Package',
            hidden: true
          }
        }
      ]
    },
    {
      path: '*',
      redirect: '/404',
      meta: { hidden: true }
    }
  ]
})

export default router
